home *** CD-ROM | disk | FTP | other *** search
/ IRIX 5.3 for Indy R4400 / IRIX 5.3 for Indy R4400 175MHz.img / dist / eoe2.idb / usr / bin / uupick.z / uupick
Text File  |  1995-02-28  |  4KB  |  172 lines

  1. #!/bin/sh
  2.  
  3. # "$Revision: 1.4 $"
  4.  
  5. # sys: system; user: login name;  cdir: current directory;
  6. # tdir: temporary directory; pu: PUBDIR/receive/user;
  7. cdir=`pwd`
  8. dir=""
  9. abs=""
  10. sys=""
  11. var=""
  12. varto=""
  13. varfrom=""
  14. trap "exit 1" 1 2 13 15
  15. # get options
  16. if test $# -gt 2
  17. then echo "Usage: $0 [-s sysname]"; exit 1
  18. fi
  19. while test $# -ge 1
  20. do
  21.     case $1 in
  22.      -s*)     if [ $# -eq 1 ]
  23.         then
  24.             sys=`expr $1 : '-s\(.*\)'`
  25.         else
  26.             sys=$2
  27.             shift
  28.         fi
  29.         if [ -z "$sys" ]
  30.         then
  31.              echo "Usage: $0 [-s sysname]"; exit 1
  32.         fi
  33.         ;;
  34.      *)    echo "Usage: $0 [-s sysname]"; exit 1
  35.     esac
  36.     shift
  37. done
  38. user=`id | sed -n "/^uid=[0-9]*(\([^)]*\)).*/s//\1/p"`
  39.  
  40. if test -z "$user"
  41. then echo "User id required!"; exit 1
  42. fi
  43.  
  44. pu=/var/spool/uucppublic/receive/$user
  45. if test -d $pu -a -s $pu
  46. then
  47. for i in `ls $pu`
  48. do
  49.     if test $sys
  50.     then    if test $sys != $i;  then continue;  fi
  51.     fi
  52.     if test -d $pu/$i -a -s $pu/$i
  53.     then
  54.         cd $pu/$i
  55.         for j in `ls -a`
  56.         do
  57.             if test $j = "." -o $j = ".."; then continue; fi
  58.             if test -d $j
  59.             then echo "from system $i: directory $j \c"
  60.             else echo "from system $i: file $j \c"
  61.             fi
  62.             while true
  63.             do
  64.               echo '? \c'
  65.               if read cmd dir
  66.               then
  67.                 trap ": ;;" 1
  68.                 case $cmd in
  69.                  d)    rm -fr $j ; break ;;
  70.                  "")    break ;;
  71. #options m, a: if dir path
  72. #begins with a slash, use full
  73. #path for destination;otherwise,
  74. #use path relative to current dir;
  75. #default destination is current dir
  76.                      m)    eval dir="$dir"
  77.                     if test $dir
  78.                      then abs=`expr "$dir" : '/.*'`
  79.                         if test $abs != 0
  80.                         then tdir=$dir
  81.                          else tdir=$cdir/$dir
  82.                         fi
  83.                     else
  84.                         tdir=$cdir
  85.                     fi
  86.                     if [ ! -d $tdir -o ! -w $tdir ]; then
  87.                         echo "directory '$tdir' doesn't exist or isn't writable"
  88.                         continue
  89.                     fi
  90.                     find $j -depth -print >/tmp/$$uupick
  91.                     cpio -pdmu $tdir </tmp/$$uupick 
  92.                     for k in `cat /tmp/$$uupick`
  93.                     do
  94.                         varto="$tdir/$k"
  95.                         varfrom="$pu/$i/$k"
  96.                         if test -f $varfrom; then
  97.                         if cmp $varfrom $varto ; then
  98.                                 rm -f $varfrom
  99.                         else
  100.                             echo "file '$varfrom' not removed"
  101.                         fi
  102.                         else
  103.                         rmdir $varfrom 2>/dev/null
  104.                         fi
  105.                     done
  106.                     rm -f /tmp/$$uupick
  107.                     break;; 
  108. #As files are transferred,
  109. #put their names in /tmp/$$uupick.
  110. #Only remove those named files
  111. #from...receive/..dir if cmp
  112. #verifies transfer took place.
  113. #then find & remove directories
  114. #(separate find is necessary because
  115. #cpio -v doesn't print dir names)
  116.                  a)    eval dir="$dir"
  117.                     if test $dir
  118.                     then abs=`expr "$dir" : '/.*'`
  119.                         if test $abs != 0
  120.                         then tdir=$dir
  121.                         else tdir=$cdir/$dir
  122.                         fi
  123.                     else
  124.                         tdir=$cdir
  125.                     fi
  126.                     if [ ! -d $tdir -o ! -w $tdir ]; then
  127.                         echo "directory '$tdir' doesn't exist or isn't writable"
  128.                         continue
  129.                     fi
  130.                     find . -depth -print | \
  131.                     grep -v '^\.$' >/tmp/$$uupick
  132.                     cpio -pdmu $tdir </tmp/$$uupick
  133.                     for k in `cat /tmp/$$uupick`
  134.                     do
  135.                         varto="$tdir/$k"
  136.                         varfrom="$pu/$i/$k"
  137.                         if test -f $varfrom; then
  138.                         if cmp $varfrom $varto ; then
  139.                             rm -f $varfrom
  140.                         else
  141.                             echo "file '$varfrom' not removed"
  142.                         fi
  143.                         else
  144.                         rmdir $varfrom 2>/dev/null
  145.                         fi
  146.                     done
  147.                     rm -f /tmp/$$uupick
  148.                     break 2 ;;
  149.                  p)    if test -d $j
  150.                     then find $j -print
  151.                     elif test -s $j 
  152.                         then cat $j
  153.                     fi ;;
  154.                  q)    break 3 ;;
  155.                  !*)    ex=`expr "$cmd $dir" : '!\(.*\)'`
  156.                     tdir=`pwd`
  157.                     cd $cdir
  158.                     sh -c "$ex"
  159.                     cd $tdir
  160.                     echo '!' ;;
  161.                  *)    echo "usage: [d][m dir][a dir][p][q]\c"
  162.                     echo "[cntl-d][!cmd][*][new-line]" ;;
  163.                 esac
  164.                 trap "exit 1" 1
  165.               else    break 3
  166.               fi
  167.             done
  168.         done
  169.     fi
  170. done
  171. fi
  172.